/* This class is a JPanel which will contain the ship sprite and its hp bar
 * 
 */

package gui.battle;

import item.ship.Ship;

import java.awt.*;

import javax.swing.*;

public class ShipPanelLeft extends JPanel {

	
	private Ship ship; //the ship on the panel
	private HPPanel hp; //the HPPanel
	private JPanel image; //the sprite of the ship
	private JLabel normalSprite; //the normal sprite
	private JLabel selectedSprite; //the selected sprite
	
	//1 param constructor that adds the ship to the panel
	public ShipPanelLeft(Ship s){

		if(s == null)
			return;
		
		this.setMinimumSize(new Dimension(300, 120));
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

		ship = s;
		
		normalSprite = new JLabel(new ImageIcon(ship.spritePath));		
		selectedSprite = new JLabel(new ImageIcon("assets\\images\\ship\\flagship\\flagship_antlion_selected.png"));
		
		
		//adds the hp bar
		hp = new HPPanel(ship);
		hp.setMaximumSize(new Dimension(50, 120));
		this.add(hp);

		//adds the actual ship to the panel
		image = new JPanel();
		image.setLayout(new GridLayout(1,1));
		image.add(new JLabel(new ImageIcon(ship.spritePath)));
		image.setMaximumSize(new Dimension(250, 120));
		
		this.add(image);
	}//Ship constructor

	
	//returns the ship on the panel
	public Ship getShip(){
		
		return ship;
	}//getShip
	
	
	//selects the ship
	public void select(){
		
		image.removeAll();
		image.add(selectedSprite);
		
		image.revalidate();
		image.repaint();
	}//select
	
	
	//deselects the ship
	public void deselect(){
		
		image.removeAll();
		image.add(normalSprite);
		
		image.revalidate();
		image.repaint();
	}//deselect
	
	
	//updates the hp bars
	public void update(){

		this.removeAll();
		hp = new HPPanel(ship);
		hp.setMaximumSize(new Dimension(50, 120));
		this.add(hp);
		this.add(image);
		
		this.revalidate();
		this.repaint();
	}//update
	

	//returns if the two passed in thing are equal
	public boolean equals(Object o){
		
		if(!(o instanceof ShipPanelLeft))
			return false;
			
		return ((ShipPanelLeft)o).ship.equals(ship);
	}//equals
}//ShipPanel